<?php

#品牌搜素权益缓存更新

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';
ini_set('memory_limit', '512M');

$brandId = $argv[1] ?? null ;

/**
 * 获取品牌
 * @return array|bool
 */
function getBrands($brandId = null)
{
    $where['status'] = \Biz\model\brand\Brand::STATUS_NORMAL;
    $where['pack_type[>]'] = 0;
    $where['uid[>]'] = 0;
    if($brandId) {
        $where['id'] = $brandId;
    }
    $result = \Biz\model\brand\Brand::select('*', $where);
    $brands = [];
    if ($result && is_array($result)) {
        $brands = $result;
    }
    return $brands;
}

$uids = [];

$brandIds = [];

$brands = getBrands($brandId);

if (!empty($brands)) {

    $uids = array_column($brands, 'uid');

    $brandIds = array_column($brands, 'id');

    \Biz\service\BrandRights\BrandRightsAllService::esCacheUpdate($uids, $brandIds);
}

var_dump(['brandIds' => $brandIds, 'uids' => $uids]);

echo "finish" . PHP_EOL;

exit;
